/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.unice.miage.oobdoo.entity;

import com.unice.miage.oobdoo.enumeration.Statut;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.FetchType;
import javax.xml.bind.annotation.*;

/**
 *
 * @author Jeremy Romano
 */
@Entity
@XmlRootElement
public class Album implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String nom;
    private String description;
    private Statut statut;
    
    @ManyToOne
    private Utilisateur auteur;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Collection<Photo> photos;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Collection<Note> notes;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Collection<Partage> partages;

    public Album() {
    }

    public Album(Utilisateur auteur, String nom, String description, Statut statut) {
        this.nom = nom;
        this.description = description;
        this.statut = statut;
        this.auteur = auteur;
        this.photos = new ArrayList<Photo>();
        this.notes = new ArrayList<Note>();
        this.partages = new ArrayList<Partage>();
    }

    public Collection<Partage> getPartages() {
        return partages;
    }

    public void setPartages(Collection<Partage> partages) {
        this.partages = partages;
    }

    public void addPartage(Partage p) {
        this.partages.add(p);
    }

    public Collection<Photo> getPhotos() {
        return this.photos;
    }

    public void addPhoto(Photo p) {
        this.photos.add(p);
    }

    public Collection<Utilisateur> getUtilisateursPartagesValide() {
        ArrayList<Utilisateur> utilisateurs = new ArrayList<Utilisateur>();
        for (Partage p : this.partages) {
            if (p.isValide()) {
                utilisateurs.add(p.getUtilisateur());
            }
        }
        return utilisateurs;
    }

    public Utilisateur getAuteur() {
        return auteur;
    }

    public void setAuteur(Utilisateur auteur) {
        this.auteur = auteur;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Statut getStatut() {
        return statut;
    }

    public void setStatut(Statut statut) {
        this.statut = statut;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getOnePicture() {
        if (this.photos.size() < 0) {
            return this.photos.iterator().next().getPathThumbHome();
        }
        return "";
    }

    public Collection<Note> getNotes() {
        return notes;
    }

    public void addNote(Note n) {
        this.notes.add(n);
    }

    @Override
    public String toString() {
        return "Album{"
                + "id="
                + id
                + " ;nom="
                + nom
                + " ;description="
                + description
                + " ;statut="
                + statut
                + '}';
    }
}
